﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ThaireInvestmentWeb.Models;
using ThaireInvestmentWeb.WcfSerivce;

namespace ThaireInvestmentWeb
{
    public class ServiceDelegate
    {

        String UserID = "TestUser";
        public ServiceDelegate()
        {
            _service = new WcfSerivce.InvestmentServiceClient();
        }
        WcfSerivce.InvestmentServiceClient _service = null;


        public FixedIncomeHeaderScreenData GetFixedIncomeHeaderScreenData()
        {
            return _service.GetFixedIncomeHeaderScreenData();
        }

        public FixedIncomeListData GetFixedIncomeListScreenData()
        {
           return  _service.GetFixedIncomeListScreenData();

        }
        public FixIncomeSecuritiesDTO InsertFixIncomeHeader(AddFixedIncomeModel model)
        {
            FixIncomeSecuritiesDTO dto = new FixIncomeSecuritiesDTO();
            dto.Header = model.Data;
            dto.RatingHistory = model.RatingHistory;
            dto.Header.CreateUserId = UserID;

            return _service.InsertFixIncomeHeader(dto);
            //return null;
        }

        public FixIncomeSecuritiesDTO UpdateFixIncomeHeader(AddFixedIncomeModel model)
        {
            FixIncomeSecuritiesDTO dto = new FixIncomeSecuritiesDTO();
            dto.Header = model.Data;
            dto.RatingHistory = model.RatingHistory;
            dto.Header.UpdateUserId = UserID;
            dto.RatingHistory.CreateUserId = UserID;
            return _service.UpdateFixIncomeHeader(dto);
            //return null;
        }

        public FixIncomeSecuritiesDTO GetFixedIncomeSecurities(int FixedIncomeSecuritiesID)
        {
            FixIncomeSecuritiesDTO dto =  _service.GetFixIncomeHeaderByID(FixedIncomeSecuritiesID);
            return dto;
        }

        public List<FixIncomeSecuritiesHeader> SearchFixedIncomeSecurities(SearchFixedIncomeSecuritiesModel model)
        {
            return new List<FixIncomeSecuritiesHeader>(_service.SearchFiexdIncome(model.ToSearchFiexdIncomeFilter()));
        }



        //TODO: temp
        public FixIncomeSecuritiesDTO InsertFixIncomePurchase(AddFixedIncomeModel model)
        {
            var dto = new FixIncomeSecuritiesDTO();
            dto.Header = model.Data;
            dto.RatingHistory = model.RatingHistory;
            dto.Header.CreateUserId = UserID;

            return _service.InsertFixIncomeHeader(dto);
            //return null;
        }
        //TODO: temp
        public List<FixincomesecuritiesPurchase> SearchFixedIncomeSecuritiesPurchases(SearchFixedIncomeSecuritiesModel model)
        {
            return new List<FixincomesecuritiesPurchase>(_service.GetFixIncomePurchasesByHeaderId(1));
        }
        //TODO: temp
        public FixIncomeSecuritiesHeader GetFixedIncomeSecuritiesHeaderById(int headerId)
        {
            return _service.GetFixedIncomeSecuritiesHeaderById(headerId);
        }

        internal FixincomesecuritiesPurchase InsertFixedIncomePurchase(FixincomesecuritiesPurchase fixincomesecuritiesPurchase)
        {
            fixincomesecuritiesPurchase.CreateUserId = UserID;
            return _service.InsertFixedIncomePurchase(fixincomesecuritiesPurchase);
        }
        internal FixIncomeSecuritiesDTO GetFixIncomeHeaderByID(int headerId)
        {
            return _service.GetFixIncomeHeaderByID(headerId);
        }
        internal IList<CounterPaties> GetAllCounterPaties()
        {
            return _service.GetAllCounterPaties();
        }

        internal IList<PaymentType> GetAllPaymentTypes()
        {
            return _service.GetAllPaymentTypes();
        }


        public FixincomesecuritiesPurchaseDTO GetFixIncomePurchaseByID(int purchaseID)
        {
            return _service.GetFixIncomePurchaseByID(purchaseID);
        }
    }
}